package lxyy.ImageDownloader.src.imageDownloader;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        ImageManager imageManager = new ImageManager();
        Scanner scanner = new Scanner(System.in);
        boolean running = true;

        System.out.println("欢迎使用网络图片下载与管理系统");

        while (running) {
            // 显示菜单
            System.out.println("\n=== 图片下载系统 ===");
            System.out.println("1. 下载图片");
            System.out.println("2. 查看所有图片");
            System.out.println("3. 搜索图片");
            System.out.println("4. 退出");
            System.out.print("请输入选项: ");

            // 处理用户输入
            try {
                int choice = Integer.parseInt(scanner.nextLine().trim());

                switch (choice) {
                    case 1:
                        System.out.print("请输入图片的URL: ");
                        String url = scanner.nextLine().trim();
                        imageManager.downloadImage(url);
                        break;
                    case 2:
                        imageManager.listImages();
                        break;
                    case 3:
                        System.out.print("请输入要搜索的图片的名称: ");
                        String name = scanner.nextLine().trim();
                        imageManager.searchImage(name);
                        break;
                    case 4:
                        running = false;
                        System.out.println("使用结束！");
                        break;
                    default:
                        System.out.println("请输入1-4之间的数字");
                }
            } catch (NumberFormatException e) {
                System.out.println("请输入数字");
            }
        }

        scanner.close();
    }
}
